package com.dzx.scala.dzxbootscala.controller

import com.dzx.scala.dzxbootscala.entity.{MetaTable, ResultVO}
import com.dzx.scala.dzxbootscala.service.MetaTableService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.{RequestMapping, RequestMethod, RestController}

/**
  * @author DuanZhaoXu
  * @ClassName:
  * @Description:
  * @date 2018年12月20日 17:44:32
  */
@RestController
@RequestMapping(value = Array("/metaTable"))
class MetaTableController @Autowired()(metaTableService: MetaTableService) {


  @RequestMapping(value = Array("/save"), method = Array(RequestMethod.GET))
  def save(metaTable: MetaTable) = {
    metaTableService.save(metaTable);
    ResultVO.success(); //scala 调用java 代码
  }

  @RequestMapping(value = Array("/query"), method = Array(RequestMethod.GET))
  def query() = {
    ResultVO.success(metaTableService.query())
  }


  @RequestMapping(value = Array("/update"), method = Array(RequestMethod.POST))
  def update(metaTable: MetaTable) = {
    if (metaTable.getId != null) {
      metaTableService.save(metaTable);
      ResultVO.success(); //scala 调用java 代码
    } else {
      ResultVO.error(1, "id不能为空")
    }
  }


  @RequestMapping(value = Array("/deleteById"), method = Array(RequestMethod.GET))
  def deleteById(id: Integer) {
    metaTableService.delete(id)
    ResultVO.success()
  }


}
